<?php

namespace App\Http\Controllers;

use App\Models\Admin;

use App\Models\Basic;
use App\Models\Pay;
use App\Models\Trade;
use App\models\Upgrade;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Mail;
use App\User;
use DB;


class TranController extends AdminController
{
    public function index(Request $request){

        $where=array();
        if(!empty($request->name)){
            $where[]=array(DB::raw("concat(firstname,lastname)"),'like',"%".$request->name."%");
        }
        if(!empty($request->email)){
            $where[]=array("users.email",'like',"%".$request->email."%");
        }
        if(!empty($request->ticket)){
            $where[]=array("ticket",$request->ticket);
        }

        $list = Trade::join("users","users.tranid","=","trades.tranid")
            ->where($where)
            ->orderby("trades.id","desc")
            ->select("trades.*","users.firstname","users.lastname","users.email as uemail")
            ->paginate(20);


        $append = array();
        $re = $request->toArray();
        foreach ($re as $key => $value) {
            $append[$key] = $value;
        }
        $list->appends($append);

        return view("tran.list",['list'=>$list]);

    }


}
